package com.china08.yxyapi.api.manage.edu.platform.statistics.resourcepandect1;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyResSubjectRepository;
import com.china08.yxyapi.service.yxyresource.statistics.ResourceSubNameCountService;

/**
 * 
 * @Description 教育局平台办公 资源统计（饼状图）备课包学科分布
 *
 * @Author LiuWeidong
 *
 * @Date 2017年12月11日
 *
 */

@CrossOrigin
@RestController
public class PackSubjectCountController extends YxyApiBaseController {

    @Autowired
    public ResourceSubNameCountService resourceSubNameCountService;
    @Autowired
    public YxyResSubjectRepository yxyResSubjectRepository;

    @RequestMapping(value = "/api_yw/manage/edu/platform/statistics/resourcepandect1/packsubject/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel req) {

        RespModel model = new RespModel();

        Integer schoolBureauLevel = getProfile(request, response).getSchoolBureauLevel();
        String districtCode = null;
        if (schoolBureauLevel == 0) {
            districtCode = getProfile(request, response).getSchoolAreaIdDistrict();
        } else if (schoolBureauLevel == 1) {
            // districtCode = getProfile(request,
            // response).getSchoolAreaIdCity();
            districtCode = getProfile(request, response).getSchoolAreaIdCity();
        } else if (schoolBureauLevel == 2) {
            districtCode = getProfile(request, response).getSchoolAreaIdProvince();
        }
        List<Long> countLst = null;

        countLst = resourceSubNameCountService.packSubjectCount(req.stageName, districtCode, schoolBureauLevel);
        List<Object> yuwenList = new ArrayList<Object>();
        List<Object> shuxueList = new ArrayList<Object>();
        List<Object> yingyuList = new ArrayList<Object>();
        List<Object> sixiangList = new ArrayList<Object>();
        List<Object> wuliList = new ArrayList<Object>();
        List<Object> huaxueList = new ArrayList<Object>();
        List<Object> lishiList = new ArrayList<Object>();
        List<Object> shengwuList = new ArrayList<Object>();
        List<Object> diliList = new ArrayList<Object>();

        List<Object> countList = new ArrayList<Object>();

        if (countLst.get(0) > 0) {
            yuwenList.add("语文");
            yuwenList.add(countLst.get(0));
            countList.add(yuwenList);
        }

        if (countLst.get(1) > 0) {
            shuxueList.add("数学");
            shuxueList.add(countLst.get(1));
            countList.add(shuxueList);
        }
        if (countLst.get(2) > 0) {
            yingyuList.add("英语");
            yingyuList.add(countLst.get(2));
            countList.add(yingyuList);
        }
        if (countLst.get(3) > 0) {
            sixiangList.add("思想政治");
            sixiangList.add(countLst.get(3));
            countList.add(sixiangList);
        }
        if (countLst.get(4) > 0) {
            wuliList.add("物理");
            wuliList.add(countLst.get(4));
            countList.add(wuliList);
        }
        if (countLst.get(5) > 0) {
            huaxueList.add("化学");
            huaxueList.add(countLst.get(5));
            countList.add(huaxueList);
        }

        if (countLst.get(6) > 0) {
            lishiList.add("历史");
            lishiList.add(countLst.get(6));
            countList.add(lishiList);
        }
        if (countLst.get(7) > 0) {
            shengwuList.add("生物");
            shengwuList.add(countLst.get(7));
            countList.add(shengwuList);
        }

        if (countLst.get(8) > 0) {
            diliList.add("地理");
            diliList.add(countLst.get(8));
            countList.add(diliList);
        }

        // String[] s = new String[9];
        // s[0] = "语文:" + countLst.get(0);
        // s[1] = "数学:" + countLst.get(1);
        // s[2] = "英语:" + countLst.get(2);
        // s[3] = "思想政治:" + countLst.get(3);
        // s[4] = "物理:" + countLst.get(4);
        // s[5] = "化学:" + countLst.get(5);
        // s[6] = "历史:" + countLst.get(6);
        // s[7] = "生物" + countLst.get(7);
        // s[8] = "地理:" + countLst.get(8);

        model.countLstObj = countList;
        return model;
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiPageReqModel {

        // 学段名称
        public String stageName;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

        public List<Object> countLstObj;

    }
}
